package cn.duhengkui.national.valuelist.gen;

import java.io.File;

import cn.duhengkui.national.valuelist.core.entity.BaseEntity;

public class DaoFactoryImpl implements DaoFactory{

	@Override
	public void createDaoFile(String daoPackage, String sourcePath, Class<? extends BaseEntity> entityClass,
			boolean readOnly) {
		String line = System.lineSeparator();//System.getProperty("line.separator");
		String daoName = entityClass.getSimpleName() + "Dao";
		StringBuffer code = new StringBuffer();
		code.append("package ").append(daoPackage).append(";").append(line).append(line);
		if(readOnly){
			code.append("import cn.duhengkui.national.valuelist.core.data.ReadOnlyDao;").append(line);
		}else{
			code.append("import cn.duhengkui.national.valuelist.core.data.StandardDao;").append(line);
		}
		code.append("import org.springframework.stereotype.Repository;").append(line);
		code.append("import ").append(entityClass.getName()).append(";").append(line).append(line);
		code.append("@Repository(\"").append(daoPackage).append(".").append(daoName).append("\")").append(line);
		code.append("public interface ").append(daoName).append(" extends ");
		if(readOnly){
			code.append("ReadOnlyDao<").append(entityClass.getSimpleName()).append(">{");
		}else{
			code.append("StandardDao<").append(entityClass.getSimpleName()).append(">{");
		}
		code.append(line).append(line);
		code.append("}");
		String path = System.getProperty("user.dir") + File.separator + sourcePath.replace("/", File.separator) + File.separator 
				+ daoPackage.replace(".", File.separator);
				CreateUtil.writeFile(path, daoName + ".java", code);
	}

}
